﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Linq;
using System.Web;

namespace DavidCms.Web.Models
{
    public class CmsContext : DbContext
    {
        public CmsContext()
            : base("CmsContextConnection")
        { }
        public DbSet<NavigationPO> Navigation { get; set; }
        public DbSet<ImagePO> Image { get; set; }
        public DbSet<ArticlePO> Article { get; set; }
        public DbSet<SettingPO> Setting { get; set; }
        public DbSet<UserPO> User { get; set; }
        public DbSet<RolePO> Role { get; set; }
        public DbSet<ModulePO> Module { get; set; }
        public DbSet<UserProfile> UserProfiles { get; set; }
    }

    [Table("tb_Business_Navigation")]
    public partial class NavigationPO
    {
        [DisplayName("编号")]
        public int Id { get; set; }
        [StringLength(50)]
        [Required]
        [DisplayName("名称")]
        public string Name { get; set; }
        [StringLength(50)]
        [Required]
        [DisplayName("英文名称")]
        public string EnglishName { get; set; }
        [StringLength(50)]
        [Required]
        [DisplayName("描述")]
        public string Description { get; set; }
        [StringLength(100)]
        [Required]
        [DisplayName("类型")]
        public string Type { get; set; }
        [DisplayName("父导航")]
        public int ParentId { get; set; }
        [DisplayName("顺序")]
        public int Order { get; set; }
        [DisplayName("显示在父导航")]
        public bool IsContentShowInParent { get; set; }
        [DisplayName("修改时间")]
        public DateTime ModifyTime { get; set; }
        [DisplayName("创建时间")]
        public DateTime CreateTime { get; set; }
        [DisplayName("激活")]
        public bool IsActive { get; set; }
    }

    public partial class NavigationPO
    {
        [StringLength(50)]
        [DisplayName("父导航")]
        public string ParentName
        {
            get
            {
                CmsContext db = new CmsContext();
                var query = db.Navigation.Where(p => p.Id == this.ParentId).FirstOrDefault();
                return query == null ? "根" : query.Name;
            }
        }
    }

    [Table("tb_Business_Image")]
    public partial class ImagePO
    {
        public int Id { get; set; }
        [StringLength(20)]
        public string Category { get; set; }
        [StringLength(50)]
        public string Name { get; set; }
        public string Description { get; set; }
        [StringLength(100)]
        public string Url { get; set; }
        public DateTime CreateTime { get; set; }
    }

    [Table("tb_Business_Article")]
    public partial class ArticlePO
    {
        public int Id { get; set; }
        [DisplayName("导航")]
        public int NavigationId { get; set; }
        [StringLength(100)]
        [DisplayName("标题")]
        public string Title { get; set; }
        [DisplayName("发布时间")]
        public DateTime publishTime { get; set; }
        [StringLength(50)]
        [DisplayName("作者")]
        public string Editer { get; set; }
        [StringLength(200)]
        [Required]
        [DisplayName("描述")]
        public string Description { get; set; }
        [DisplayName("内容")]
        public string Content { get; set; }
        [DisplayName("创建时间")]
        public DateTime CreateTime { get; set; }
    }

    public partial class ArticlePO
    {
        CmsContext db = new CmsContext();
        [DisplayName("导航名称")]
        [StringLength(50)]
        public string NavigationName
        {
            get
            {
                var query = db.Navigation.Where(p => p.Id == this.NavigationId).FirstOrDefault();
                return query.Name;
            }
        }

        [DisplayName("英文导航名称")]
        [StringLength(50)]
        public string NavigationEnglishName
        {
            get
            {
                var query = db.Navigation.Where(p => p.Id == this.NavigationId).FirstOrDefault();
                return query.EnglishName;
            }
        }
    }

    [Table("tb_Common_Setting")]
    public partial class SettingPO
    {
        public int Id { get; set; }
        public int ParentId { get; set; }
        [StringLength(50)]
        public string Name { get; set; }
        [StringLength(50)]
        public string Description { get; set; }
        public DateTime CreateTime { get; set; }
        public bool IsActive { get; set; }
    }

    [Table("tb_Power_User")]
    public partial class UserPO
    {
        public int Id { get; set; }
        [StringLength(50)]
        public string Code { get; set; }
        [StringLength(50)]
        public string Name { get; set; }
        [StringLength(50)]
        public string Password { get; set; }
        public int RoleId { get; set; }
        public DateTime CreateTime { get; set; }
        public bool IsActive { get; set; }
    }

    [Table("tb_Power_Role")]
    public partial class RolePO
    {
        public int Id { get; set; }
        [StringLength(50)]
        public string Name { get; set; }
        [StringLength(50)]
        public string Description { get; set; }
        public int Level { get; set; }
        public DateTime CreateTime { get; set; }
        public bool IsActive { get; set; }
    }

    [Table("tb_Power_Module")]
    public partial class ModulePO
    {
        public int Id { get; set; }
        [StringLength(50)]
        public string Name { get; set; }
        [StringLength(50)]
        public string Description { get; set; }
        [StringLength(100)]
        public string Url { get; set; }
        public int type { get; set; }
        public DateTime CreateTime { get; set; }
        public bool IsActive { get; set; }
    }
}